
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link type="text/css" rel="stylesheet" href="/css/faqi.css">
<link type="text/css" rel="stylesheet" href="/css/common.css">
<script type="text/javascript" src="/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="/js/layer/layer.js"></script>
	<script type="text/javascript" src="/js/common.js"></script>
	<link type="text/css" rel="stylesheet" href="/js/webuploader-0.1.5/webuploader.css">
	<script type="text/javascript" src="/js/webuploader-0.1.5/webuploader.js"></script>

<script type="text/javascript">
$(document).ready(function(){

	var detailUploader = new WebUploader.Uploader({
		auto: true,
		fileVal: 'file',
		swf: 'js/webuploader-0.1.5/Uploader.swf',
		server: '/general/upload?path=project/item',
		pick: $("#progressUploadPic"),
		accept: {
			title: 'Images',
			extensions: 'gif,jpg,jpeg,bmp,png',
			mimeTypes: 'image/jpg,image/jpeg,image/png'
		}
	});
	var div = $("#upload_detital_picIMGBOX");
	detailUploader.on("uploadSuccess", function (file, res){
		console.log(res);
		div.append('<img src=' + res.data + ' />');
	})

})

/**
 * 保存开始textarea纯文本的val
 */
function addTextArray(){
	textArr = [];
	$("#detail_info textarea").each(function(){

		textArr.push($(this).val());

	})

}

/**
 * 详情内容+图片转换成html
 */

function textToHtml(obj){
	var img ="";

	re = new RegExp("\n", "g");
	obj.each(function(){
		//alert($(this).parent().parent().find("img").length);

		$(this).parent().parent().find("img").each(function(){
			//var $this = $(this).parent().parent().find("img");

			img = img + "<img src='"+$(this).attr("src") +"' class='lazy' style='width:670px; height:100%' />";

		})
		$(this).val("<p>"+$(this).val().replace(re,"</p><p>")+"</p>"+img);

		img ="";//清空

	})
}

//更新项目最新动态
function updateProjectProcess(){

	addTextArray();//保存开始的文本

	textToHtml($("#detail_info textarea")); //textare的value转htnl

	//内容
	var projectId = getQueryVariable('project_id');
	var content = $("#updateProjectProgress textarea[name='detail_content1']").val();

	let token = localStorage.getItem("crowdfunding-token");
	$.ajax({
		url: API_BASE_URL + "/front/project/updateProgress",
		data:JSON.stringify({projectId:projectId,content:content}),
		async:false,
		headers: {
			"Authorization": token ? ('Bearer ' + JSON.parse(token).token) : ''
		},
		type: "POST", //请求方式为POST
		contentType: 'application/json;charset=utf-8',
		dataType:"json",
		success:function(res){

			if (res.code == 401) {
				layer.alert("登录过期！！！")
			} else if(res.code==200){
				layer.confirm(res.message, {
					btn: ['确定'], //按钮
				}, function(){
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				});
			}else{
				var index =layer.confirm(res.message, {
					btn: ['确定'], //按钮
					closeBtn:0
				}, function(){
					layer.close(index);
				});
			}




			renewText();
		}
	});




	/*

        //询问框
        layer.confirm('发布成功', {
          btn: ['确定'], //按钮
          closeBtn:0
        }, function(){
          //layer.msg('的确很重要', {icon: 1});
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
    */

}

</script>

<title></title>
</head>
<body>

<div class="pj_fq">
	
    <!--项目信息begin-->
   	<div class="fq_bodyBox" style="min-height:100%">
	   	<div class="fq_bodyMainBox" style="width:890px">
	        
	        <!--项目详细描述begin-->
	        <div id="updateProjectProgress">
	      
	        <div class="fq_body1 xxr3">
	        	
	            	
	                
	               <div class="fq_body1_content">
	               <form id="detail_info">
	                <input type="hidden" name="detailCount" value="3">
	                	<div class="fq_body_ul detail">
<!-- 		                	<form> -->
		                    	 
		                      
		                        <div class="text_body">
		                        	<textarea  name="detail_content1" ></textarea>
		                        </div>
		                        
		                        
		                        <div id="upload_detital_picIMGBOX" style="" class="upload_detital_pic">
		                        	
		                        </div>

		                        
		                        
		                        <div id="content_picBox">
		                       
									<div class="content_picBox">
								    	<div class="pic_top">
								        	<span class="content_pic_span">上传照片(可选)</span>
								            
								        </div>
								        <div calss="pic_bottom">
											<div class="button_pic">
												<div id="progressUploadPic" class="uploadPic"></div>
											</div>

								            <p class="pic_bottom_p">支持JPG、GIF、PNG格式的图片，不超过1M大小</p>
								        </div>
								    </div>
								    
								</div>
							
		                        
<!-- 		                    </form> -->
	                    </div>
	                
	
	                </form>
	             </div>   
	
	                
	            </div>
	            
	           </div>
	       
	        
	        <!--项目详细描述end-->
	        

	        
	  
	        
	    </div>
	    <!--项目信息end-->
	    <div class="fq_footer" style="width:890px">
	    	
	        <a href="javascript:updateProjectProcess();" class=" big btn  btn-blue ">发布</a>
	    </div>
	</div>
</div>
<!--项目发起end-->


</body>
</html>